//
// Created on 2025/6/25.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef CANVASTEST_SKOHIMAGECODEC_H
#define CANVASTEST_SKOHIMAGECODEC_H

#include "codec/SkCodec.h"
#include <multimedia/image_framework/image/image_source_native.h>
class SkOHImageCodec : SkCodec {
public:
    static std::unique_ptr<SkCodec> makeFromData(sk_sp<SkData> data);
    
    ~SkOHImageCodec();
    
protected:

    SkEncodedImageFormat onGetEncodedFormat() const override;
    
    Result onGetPixels(const SkImageInfo& info,
                               void* pixels, size_t rowBytes, const Options&,
                               int* rowsDecoded) override;
    
    std::tuple<sk_sp<SkImage>, SkCodec::Result> onGetImage(const SkImageInfo& info,
                                                         const Options* opts = nullptr) override;
    
    int onGetFrameCount() override;

    bool onGetFrameInfo(int, FrameInfo*) const override;

    int onGetRepetitionCount() override;
    
    int onOutputScanline(int inputScanline) const override;
    
    bool conversionSupported(const SkImageInfo& dst, bool srcIsOpaque,
                                     bool needsColorXform) override;
    
private:
    
    SkOHImageCodec(SkEncodedInfo&& info,
                 XformFormat srcFormat,
                 std::unique_ptr<SkStream> stream,
                 SkEncodedOrigin origin,
                 OH_ImageSourceNative *source,
                 int loopCnt);
    
    
    OH_ImageSourceNative *fSource = nullptr;
    
    std::vector<FrameInfo> fFrameInfo;

    int fRepetitionCount = -1;
};

#endif //CANVASTEST_SKOHIMAGECODEC_H
